package com.dbdoc.controller;

import com.dbdoc.service.ICompanyInfoBaseService;
import com.dbdoc.entity.CompanyInfoBase;
import com.dbdoc.config.BasePage;
import com.dbdoc.util.ResultJson;
import org.springframework.beans.factory.annotation.Autowired;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.Api;
import org.springframework.web.bind.annotation.*;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;


/**
 * @author liuChengWen
 * @since 2020-12-28
 */
@Api(tags = "企业信息基础表 - Controller")
@RestController
@RequestMapping("/dbdoc/companyInfoBase")
    public class CompanyInfoBaseController {

    @Autowired
    private ICompanyInfoBaseService iCompanyInfoBaseService;

    @ApiOperation(value = "添加 - company_info_base")
    @PostMapping(value = "insert")
    public ResultJson insert(@RequestBody CompanyInfoBase model){
        boolean flag=iCompanyInfoBaseService.save(model);
        if(flag){
             return ResultJson.ok();
        }else{
             return ResultJson.error();
        }
    }

    @ApiOperation(value = "修改 - company_info_base")
    @PostMapping(value = "up/{id}")
    public ResultJson update(@RequestBody CompanyInfoBase model){
        boolean flag=iCompanyInfoBaseService.updateById(model);
        if(flag){
            return ResultJson.ok();
        }else{
            return ResultJson.error();
        }
    }

    @ApiOperation(value = "删除 - company_info_base")
    @PostMapping(value = "delete/{id}")
    public ResultJson delete(@PathVariable("id") Integer id){
        boolean flag=iCompanyInfoBaseService.removeById(id);
        if(flag){
            return ResultJson.ok();
        }else{
            return ResultJson.error();
        }
    }

    @ApiOperation(value = "列表查询 - company_info_base")
    @PostMapping(value = "pageList")
    public ResultJson pageList(@RequestBody BasePage<CompanyInfoBase> basePage){
        if(basePage.is_search()){
             return ResultJson.ok(iCompanyInfoBaseService.pageList(basePage.getData(),basePage.getPageNumber(),basePage.getPageSize()));
        }else{
             return ResultJson.ok(iCompanyInfoBaseService.list(new QueryWrapper(basePage.getData())));
        }
    }

}

